package com.anlu.base.system;

import com.anlu.base.system.legacy.LegacyOrder;
import com.anlu.base.system.legacy.LegacyShop;
import com.anlu.base.system.modern.Customer;
import com.anlu.base.system.modern.ModernOrder;
import com.anlu.base.system.modern.Shipment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class AntiCorruptionLayer {

    @Autowired
    private LegacyShop legacyShop;


    public Optional<ModernOrder> findOrderInLegacySystem(String id){
        return legacyShop.findOrder(id).map(legacyOrder -> new ModernOrder(legacyOrder.getId(),
                new Customer(legacyOrder.getCustomer()),
                new Shipment(legacyOrder.getItem(), legacyOrder.getQty(), legacyOrder.getPrice()),
                ""));
    }
}
